<template>
  <div id="app">
    <div class="header">网页头部</div>
    <div class="content">
      <CartHeader :list="this.$store.state.list" @changeAll="changeAll" />
      <CartList :list="this.$store.state.list" />
      <CartFooter
        :list="this.$store.state.list"
        @clearCart="clearCart"
        @delAllSelect="delAllSelect"
      />
    </div>
    <div class="footer">网页底部</div>
  </div>
</template>

<script>

import CartHeader from "./components/CartHeader.vue";
import CartList from "./components/CartList.vue";
import CartFooter from "./components/CartFooter.vue";
export default {
  name: "App",
  data() {
    return {
     
    };
  },
  computed:{

  },
  methods: {
    //
     //删除该项
    delOneGood(id) {
      this.$store.commit("delOne",id);
    },
    //切换全选/全不选
    changeAll(value) {
      // this.list.forEach((item) => {
      //   //每次触发都全选了
      //   item.select = true;
      // });
       this.$store.commit("toggleAll",value);
    },
    //清空购物车
    clearCart() {
      this.$store.commit("clearAll");
    },
    //删除选中项
    delAllSelect() {    
    this.$store.commit("delSelects");
    },
  },
  components: { CartHeader, CartList, CartFooter },
  mounted() {
    // this.$bus.$on("delOneGood", 你要执行的方法);
    this.$bus.$on("delOneGood", this.delOneGood);
  },
};
</script>
<style>
* {
  margin: 0;
  padding: 0;
}

ul,
ol,
li {
  list-style: none;
}

input,
button,
textarea {
  outline: none;
  border: none;
}

a,
a:hover,
a:target,
a:link,
a:active {
  text-decoration: none;
  color: #333;
}

a,
img {
  width: 100%;
  height: 100%;
  display: block;
}
.header,
.footer {
  width: 1200px;
  height: 80px;
  background-color: skyblue;
  color: #fff;
  font-size: 36px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0 auto;
}

.footer {
  height: 300px;
  font-size: 100px;
}
.content {
  width: 1200px;
  padding: 10px 0;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}
</style>
